//
//  WZLoginNetWorkAPI.swift
//  OfficeExaminationSwift
//
//  Created by Yeeewz on 2018/1/10.
//  Copyright © 2018年 Yeeewz. All rights reserved.
//

import Foundation
import Moya
import CryptoSwift


let loginProvider = MoyaProvider<Login>()

public enum Login{
    case login(String,String)
    case register
}

extension Login: TargetType{
    public var baseURL: URL {
        return URL(string: "http://120.27.10.241:8080/workService/service.action?")!
    }
    
    public var path: String {
        return ""
    }
    
    public var method: Moya.Method {
        return .post
    }
    
    public var sampleData: Data {
        return "{}".data(using: String.Encoding.utf8)!
    }
    
    public var task: Task {
        switch self {
        case .login(let phone, let password):
            var params: [String: Any] = [:]
            params["cmd"] = "userLogin"
            params["phone"] = phone
            params["password"] = password.md5()
            params["token"] = "1a1018970aa3c8cfd93"
            print(params)
        
            return .requestParameters(parameters: converDictionaryToJsonDic(dic: params as [String:AnyObject]) , encoding: URLEncoding.default)
            
        default:
            return .requestPlain
        }
    }
    
    public var headers: [String : String]? {
        return nil
    }
    public var validate: Bool{
        return false
    }
    

}
